package com.kobe.Management.controller;

import com.kobe.Management.domain.Management;
import com.kobe.Management.service.ManagementService;
import com.kobe.common.core.controller.BaseController;
import com.kobe.common.core.domain.AjaxResult;
import com.kobe.common.core.page.TableDataInfo;
import com.kobe.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.List;


@RestController
@RequestMapping("/kobe/Management")
public class ManagementController extends BaseController {

    @Autowired
    private ManagementService managementService;

        /**
         * 查询所有文章
         * @return 文章列表
         */
        @RequestMapping("/list")
        public TableDataInfo listArticle(Management management) {
            startPage();
            List<Management> list = managementService.listArticle(management);
            return getDataTable(list);
        }
                /**
                 * 查询文章详情
                 * @param articleId 文章id
                 * @return 文章详情
                 */
                @RequestMapping("/{articleId}")
                public Management getArticle(@PathVariable BigInteger articleId) {
                    return managementService.getArticle(articleId);
                }
                /**
                 * 新增文章
                 * @param management 文章信息
                 * @return 新增结果
                 */
                @RequestMapping("/add")
                public AjaxResult insertArticle(@RequestBody Management management) {
                    management.setCreateBy(SecurityUtils.getUsername());
                    management.setCreateTime(LocalDateTime.now());
                    int result = managementService.insertArticle(management);
                    return AjaxResult.success("新增成功");
                }
                /**
                 * 更新文章
                 * @param management 文章信息
                 * @return 更新结果
                 */
                @RequestMapping("/update")
                public AjaxResult updateArticle(@RequestBody Management management) {
                    management.setUpdateBy(SecurityUtils.getUsername());
                    management.setUpdateTime(LocalDateTime.now());
                    int result = managementService.updateArticle(management);
                    return AjaxResult.success("更新成功");
                }
}
